﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace ResourceBlender_Express {
    public class AlternatingRowSelector : StyleSelector {
        private int i = 0;
        /// <summary>
        /// When overridden in a derived class, returns a <see cref="T:System.Windows.Style"/> based on custom logic.
        /// </summary>
        /// <param name="item">The content.</param>
        /// <param name="container">The element to which the style will be applied.</param>
        /// <returns>
        /// Returns an application-specific style to apply; otherwise, null.
        /// </returns>
        public override Style SelectStyle(object item, DependencyObject container) {
            // makes sure the first item always gets the first style, even when restyling
            ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(container);
            if(item == ic.Items[0]) {
                i = 0;
            }
            //todo: fix alternating rows
            string styleKey;
            if(i % 2 == 0) {
                styleKey = "";
            } else {
                styleKey = "AltListViewItem";
            }
            i++;
            return styleKey == "" ? null : (Style)(ic.FindResource(styleKey));
            //return (Style)(ic.FindResource(styleKey));
        }
    }
}
